package com.liu.usky.rlzp.uskyrlzp.util;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

public class MyEventBus {

    // 定义一种类型的消息
    static class MqTest{}
    static class StatusTest{}

   static class OneCustomer{
       @Subscribe
       public void customerMq(MqTest mqTest){
            System.out.println(mqTest.getClass().getCanonicalName() + "work");
       }

       @Subscribe
       public void customerStatus(StatusTest statusTest){
           System.out.println(statusTest.getClass().getCanonicalName() + "work");
       }
   }

    static class TwoCustomer{
        @Subscribe
        public void customerMq(MqTest mqTest){
            System.out.println(mqTest.getClass().getCanonicalName() + " other work");
        }

    }

    public static void main(String[] args) {

       // 初始化消息总线

        EventBus eventBus = new EventBus();
        eventBus.register(new MyEventBus.OneCustomer());
        eventBus.register(new MyEventBus.TwoCustomer());

        // 将消息推送给消费者
        eventBus.post(new MyEventBus.MqTest());
        eventBus.post(new MyEventBus.StatusTest());

    }

}
